# list1=[1,2,3,4,5]
# print(list1)
# list1.append(6)
# print(list1)
# del list1[2]
# print(list1)
# list1.insert(1,8)
# print(list1)
# i=9
# for g in list1:
#     if i==g :
#         print('有这个元素')
#     else:
#         print("没有这个元素")
#         break
# list2=[7,8,9]
# for g in list2:
#     list1.append(g)
#     print(list1)

# list2=[10,11,12]
# list1=list1+list2
# print(list1)
#
# list1.insert(2,13)
# list1.insert(2,14)
# print(list1)

# mylist=[3,'elderberry',9,'data',7,'cherry',2,'banana',5,'apple']
# mylist.append('fig')
# print(mylist)
# del mylist[3]
# # mylist.pop(3)
# print(mylist)
# del mylist[4]
# mylist.insert(5,'grape')
# print(mylist)

# 查找cherry
# i=0
# for a in mylist:
#     if a=='cherry':
#         print(i)
#         break
# i+=1
# 遍历mylist并打印
# for g in mylist:
#     print(g)

#在cherry后面插入kiwi
# i=0
# for y in mylist:
#     if y=="cherry":
#         mylist.insert(i+1,'kiwi')
#         print(mylist)
#         break
#     i+=1

# 索引并打印倒数第三个索引
# for t in mylist:
#      if t == mylist[2]:
#          print(t)
#          break

#使用负数索引找到并打印倒数第二个元素
# for u in mylist:
#     if u==mylist[-2]:
#         print(u)

# 使用切片操作反转整个列表并打印结果
# print(mylist[::-1])

# 对列表中的字符串进行排序，并保留数字在原位
# mylist=[3,'elderberry',9,'data',7,'cherry',2,'banana',5,'apple']
# list3=[]
# i=0
# u=0
# n=0
# for b in mylist:
#     if type(b)== type(''):
#         list3.append(b)
#         print(i)
#     i+=1
# list3.sort()
# print(list3)
# for b in mylist:
#     if type(b) is str:
#         mylist[u] = list3[n]
#         n+=1
#     u+= 1
# print(mylist)
# i=0
# for u in mylist:
#     if type(u) is int:
#         mylist[i]=str(u)
#     i+=1
#
# print(mylist)

# for i in range(50):
#     list1[i]=list1[i]**2
# result=[num for num in list1 if num<1000]
# print(result)
#
# list1=result[::-1]
# print(list1)
# 列表改字典，列表元素值为key，列表索引值为value
# list1=list(range(2,101,2))
# list2=list(range(2,101,2))
# m=0
# for g in list1:
#     list2[m]=m
#     m+=1
# dictory=dict(zip(list1,list2))
# print(dictory)
import random

list1=list(range(2,101,2))
# for index,elem in enumerate(list1,start=0):
#     print(f'索引:{index},元素:{elem}')
# num=random.choice(list1)
# print(num)
my_list = ["apple", "banana", "cherry"]
file_path = "output.txt"  # 保存的文件名

with open(file_path, "w", encoding="utf-8") as file:
    for element in my_list:
        file.write(f"{element}\n")  # 写入元素并添加换行符
# for g in list1:
#     if type(g) is int:
#         list1[m]=float(g)
#     m+=1
# print(list1)
# for g in list1:
#     if g>50:
#         list1[m]=g
#         m+=1
# print(list1)

# list1.sort(reverse=True)
# print(list1)
# list1=list1[:10:1]
# print(list1)
# list2=[101,102,103]
# list1=list1+list2
# print(list1)
# sum=0
# i=0
# for g in list1:
#     sum=sum+g
#     i+=1
# print(sum)
# a=sum/i
# print(round(a,2))

# i=list1[0]
# u=list1[0]
# for g in list1:
#     if i<g:
#         i=g
# print(i)
# for g in list1:
#     if u>g:
#         u=g
# print(u)








